package com.wtp.wallpaper.rabbitmq.config;

import jakarta.annotation.Resource;
import org.springframework.amqp.rabbit.annotation.EnableRabbit;
import org.springframework.amqp.rabbit.listener.RabbitListenerEndpointRegistry;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.Lifecycle;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Service;

@EnableRabbit
@Configuration
public class RabbitListenerConfig {

    @Resource
    private RabbitListenerEndpointRegistry registry;

    // 暂停所有监听器
    public void stopAllConsumers() {
        //registry.getListenerContainer()
        registry.getListenerContainers().forEach(Lifecycle::stop);
    }

    // 启动所有监听器
    public void startAllConsumers() {
        registry.getListenerContainers().forEach(Lifecycle::start);
    }
}
